﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace PSE.AuditLogging.StorageService.Configuration
{
    [ConfigurationCollection(typeof(InstanceConfigurationElement), AddItemName = "instance")]
    public class InstanceConfigurationElementCollection : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new InstanceConfigurationElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((InstanceConfigurationElement)element).InstanceId;
        }

        public new InstanceConfigurationElement this[string key]
        {
            get
            {
                return (InstanceConfigurationElement)BaseGet(key);
            }
            //set
            //{
            //    this.BaseRemove(key);
            //    this.BaseAdd(value);
            //}
        }

        public new InstanceConfigurationElement this[int index]
        {
            get
            {
                return (InstanceConfigurationElement)BaseGet(index);
            }
        }

        public void Add(InstanceConfigurationElement item)
        {
            base.BaseAdd(item);
        }

        public void Remove(string instanceId)
        {
            if (base.BaseGet(instanceId) != null) //se existe
                base.BaseRemove(instanceId);
        }
    }
}
